package cn.yuanqiao.web.controller.archive.storeRoom;

import cn.yuanqiao.archive.storeRoom.domain.Grid;
import cn.yuanqiao.archive.storeRoom.domain.Shelf;
import cn.yuanqiao.archive.storeRoom.service.IShelfService;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 档案柜Controller
 * 
 * @author xy
 * @date 2023-06-19
 */
@RestController
@RequestMapping("/archive/shelf")
public class ShelfController extends BaseController
{
    @Autowired
    private IShelfService shelfService;

    /**
     * 查询档案柜列表
     */
/*
    @PreAuthorize("@ss.hasPermi('storeroom:shelf:list')")
*/
    @GetMapping("/list")
    public TableDataInfo list(Shelf shelf)
    {
        startPage();
        List<Shelf> list = shelfService.selectShelfList(shelf);
        return getDataTable(list);
    }

    /**
     * 导出档案柜列表
     */
/*
    @PreAuthorize("@ss.hasPermi('storeroom:shelf:export')")
*/
    @Log(title = "档案柜", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Shelf shelf)
    {
        List<Shelf> list = shelfService.selectShelfList(shelf);
        ExcelUtil<Shelf> util = new ExcelUtil<Shelf>(Shelf.class);
        util.exportExcel(response, list, "档案柜数据");
    }

    /**
     * 获取档案柜详细信息
     */


    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:warehouseInformation:shelf:detail')")
    @GetMapping(value = "/{shelfId}")
    public AjaxResult getInfo(@PathVariable("shelfId") Long shelfId)
    {
        return success(shelfService.selectShelfByShelfId(shelfId));
    }

    /**
     * 新增档案柜
     */


    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:warehouseInformation:shelf:edit')")
    @Log(title = "档案柜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shelf shelf)
    {
        return toAjax(shelfService.insertShelf(shelf));
    }

    /**
     * 修改档案柜
     */
/*
    @PreAuthorize("@ss.hasPermi('storeroom:shelf:edit')")
*/
    @Log(title = "档案柜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shelf shelf)
    {
        return toAjax(shelfService.updateShelf(shelf));
    }

    /**
     * 删除档案柜
     */


    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:warehouseInformation:shelf:delete')")
    @Log(title = "档案柜", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shelfIds}")
    public AjaxResult remove(@PathVariable Long[] shelfIds)
    {
        return toAjax(shelfService.deleteShelfByShelfIds(shelfIds));
    }

    /**
     * 验证该是否可进行修改
     */
    @GetMapping(value = "/checkShelf/{shelfId}")
    public AjaxResult checkShelf(@PathVariable("shelfId") Long shelfId)
    {
        int num=shelfService.checkShelf(shelfId);
        if(num>0){
            return AjaxResult.success(500);
        }else{
           return AjaxResult.success(200) ;
        }
    }

    //获取档案格的详情
    @GetMapping(value = "/getGridInfo")
    public TableDataInfo getGridInfo(Shelf shelf) {
        startPage();
        List<Grid> list = shelfService.getGridInfo(shelf.getShelfId());
        return getDataTable(list);
    }



    //获取档案格的详情
    @GetMapping(value = "/getGridList/{shelfId}")
    public TableDataInfo getGridList(@PathVariable("shelfId") Long shelfId) {
        List<Grid> list = shelfService.getGridInfo(shelfId);
        return getDataTable(list);
    }






}
